import { usePost } from "@/utils/http"
import { md5 } from "js-md5"

const apiModulePrefix = "/ucenter"

const profile = async () => {
    return usePost("/profile", {}, { apiModulePrefix })
}

interface UpdateProfileParams {
    nickname: string
    gender: string
    mobile: string
    email: string
}

const updateProfile = async (params: Partial<UpdateProfileParams>) => {
    return usePost("/updateProfile", params ?? {}, { apiModulePrefix, successFn: true })
}

interface UpdatePasswordParams {
    oldPwd: string
    newPwd: string
    newPwdRepeat: string
}

const updatePassword = async (params: UpdatePasswordParams) => {
    params.oldPwd = md5(params.oldPwd)
    params.newPwd = md5(params.newPwd)
    params.newPwdRepeat = md5(params.newPwdRepeat)
    return usePost("/updatePassword", params ?? {}, { apiModulePrefix, successFn: true })
}

export const api = { profile, updateProfile, updatePassword }
